//
//  ProgressCell.m
//  Tunnel
//
//  Created by wbb on 2025/6/18.
//

#import "ProgressCell.h"
#import "YJXYModel.h"
#import "SDWebImage.h"
#import "GJSCImageView.h"
@interface ProgressCell()
@property (nonatomic, strong) UIView * lineView;

@property (nonatomic, strong) UILabel * titleLab;
@property (nonatomic, strong) UILabel * detailLab;
@property (nonatomic, strong) UILabel * timeLab;
@property (nonatomic, strong) UIStackView * stackView;

@end
@implementation ProgressCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self) {
        [self initUI];
    }
    return self;
}

- (void)initUI {
    
    UIView *tagView = [[UIView alloc] init];
    tagView.backgroundColor = [UIColor clearColor];
    tagView.cornerRadius = 6;
    tagView.borderWidth = 1;
    tagView.borderColor = main_color;
    [self.contentView addSubview:tagView];
    [tagView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(10);
        make.left.offset(15);
        make.width.height.offset(12);
    }];
    
    UIView *tagView1 = [[UIView alloc] init];
    tagView1.backgroundColor = main_color;
    tagView1.cornerRadius = 3;
    [self.contentView addSubview:tagView1];
    [tagView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(tagView);
        make.width.height.offset(6);
    }];
    
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = main_color;
    [self.contentView addSubview:lineView];
    self.lineView = lineView;
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(tagView.mas_bottom).offset(5);
        make.centerX.equalTo(tagView.mas_centerX);
        make.width.offset(1);
        make.bottom.offset(0);
    }];
    
    UILabel *titleLab = [[UILabel alloc] init];
    self.titleLab = titleLab;
    titleLab.text = @"运行值班长  李佳睿";
    titleLab.textColor = main_text_color;
    titleLab.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:titleLab];
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(tagView.mas_right).offset(15);
        make.centerY.equalTo(tagView.mas_centerY);
        make.right.offset(-25);
    }];
    
    UILabel *detailLab = [[UILabel alloc] init];
    detailLab.text = @"事故现场情况严峻，有两人重伤，一人死亡。车龙拥堵至洞 外10米。事故现场情况严峻，有两人重伤，一人死亡。车龙拥堵至洞 外10米。事故现场情况严峻，有两人重伤，一人死亡。车龙拥堵至洞 外10米。事故现场情况严峻，有两人重伤，一人死亡。车龙拥堵至洞 外10米。事故现场情况严峻，有两人重伤，一人死亡。车龙拥堵至洞 外10米。";
    detailLab.textColor = main_light_text_color_6;
    detailLab.numberOfLines = 0;
    self.detailLab =detailLab;
    detailLab.font = [UIFont systemFontOfSize:11];
    [self.contentView addSubview:detailLab];
    [detailLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(titleLab);
        make.top.equalTo(titleLab.mas_bottom).offset(8);
    }];
    
    UILabel *timeLab = [[UILabel alloc] init];
    timeLab.text = @"2025-12-12 15:12:12";
    timeLab.textColor = main_light_text_color_9;
    timeLab.font = [UIFont systemFontOfSize:11];
    [self.contentView addSubview:timeLab];
    self.timeLab = timeLab;
    [timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(titleLab);
        make.top.equalTo(detailLab.mas_bottom).offset(8);
    }];
    
    
//    UIStackView *stackView = [[UIStackView alloc] init];
//    stackView.spacing = 10;
//    stackView.distribution = UIStackViewDistributionEqualSpacing;
//    [self.contentView addSubview:stackView];
//    
//    
//    for (int i = 0; i<3; i++) {
//        UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake( 0 , 0, 44, 44)];
//        imgView.hidden = YES;
//        imgView.tag = 10+i;
//        [stackView addArrangedSubview:imgView];
//    }
//    
//    [stackView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(titleLab);
//        make.top.equalTo(timeLab.mas_bottom).offset(8);
//        make.height.offset(44);
//        make.bottom.offset(-8);
//    }];
//    self.stackView = stackView;
}

- (void)cellWithData:(NSArray *)data andIndex:(NSInteger)index {
    
    RtContingencyEventHandleDto *model = data[index];
    self.lineView.hidden = index == data.count -1;
    
    self.titleLab.text = model.czrMc;
    self.detailLab.text = model.cznr;
    if(self.stackView){
        [self.stackView removeFromSuperview];

    }
    
    NSArray *imgList = model.fjList;
    
    UIStackView *stackView = [[UIStackView alloc] init];
    stackView.spacing = 10;
    stackView.distribution = UIStackViewDistributionEqualSpacing;
    [self.contentView addSubview:stackView];
    for (int i = 0; i<imgList.count; i++) {
        UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake( 0 , 0, 44, 44)];
        YJFJModel * fj = imgList[i];
        // 设置图片
        [imgView sd_setImageWithURL:[NSURL URLWithString:fj.url] placeholderImage:[UIImage imageNamed:@"yxjc_icon"]];
        [imgView addTarget:self action:@selector(openImgView:)];
        [stackView addArrangedSubview:imgView];
      
    }
    [stackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.detailLab);
        make.top.equalTo(self.timeLab.mas_bottom).offset(8);
        make.width.offset(44 + (44+10)*(imgList.count-1));
        make.height.offset(imgList.count>0?44:0);
        make.bottom.offset(-8);
    }];
    self.stackView = stackView;
}
- (void)openImgView:(UIGestureRecognizer *)gr {
    GJSCImageView *scImgView = (GJSCImageView *)[GJSCImageView nibView];
    [kWindow addSubview:scImgView];
    [scImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.offset(0);
    }];
    UIImageView * imgv = (UIImageView*)gr.view;
    scImgView.image = imgv.image;
}
@end
